﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CJJCH.Web.Manage
{
    public partial class MainMenu : System.Web.UI.Page
    {
        CJJCH.BLL.T_NET_MenuFirst bll_frist = new BLL.T_NET_MenuFirst();
        CJJCH.BLL.T_NET_MenuSecond bll_second = new BLL.T_NET_MenuSecond();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RepeaterDataBinding();
            }
        }

        private void RepeaterDataBinding()
        { 
            IList<CJJCH.Model.T_NET_MenuFirst> list = new List<CJJCH.Model.T_NET_MenuFirst>();
            list = bll_frist.GetMenuFirstList("");
            rptMenu.DataSource = list;
            rptMenu.DataBind();
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                HtmlGenericControl divMenu = (HtmlGenericControl)e.Item.FindControl("divMenu");
                HtmlGenericControl divSubMenu = (HtmlGenericControl)e.Item.FindControl("divSubMenu");
                ((HyperLink)e.Item.FindControl("lnkMenu")).Text = ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).MenuName;
                ((HyperLink)e.Item.FindControl("lnkMenu")).Attributes.Add("onclick", "MenuClick('" + divMenu.ClientID + "','" + divSubMenu.ClientID + "')");
                IList<CJJCH.Model.T_NET_MenuSecond> list = new List<CJJCH.Model.T_NET_MenuSecond>();
                int FirstID = ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).ID;
                list = bll_second.GetMenuSecondList(0,FirstID);
                if (list.Count>0)
                {
                    Repeater rptSubMenu = (Repeater)e.Item.FindControl("rptSubMenu");
                    rptSubMenu.DataSource = list;
                    rptSubMenu.DataBind();
                }
            }
        }

        protected void rptSubMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
                int typeId = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID;
                string url = "";
                switch (typeId)
                {
                    case 1:
                        url = "NoteList.aspx";
                        break;
                    case 2:
                        url = "NewsList.aspx";
                        break;
                    case 3:
                        url = "DownloadList.aspx";
                        break;
                    case 4:
                        url = "ExpertList.aspx";
                        break;
                    case 5:
                        url = "ConsultingList.aspx";
                        break;
                    case 6:
                        url = "StandardsList.aspx";
                        break;
                    case 7:
                        url = "OnlineList.aspx";
                        break;
                    case 8:
                        url = "NormList.aspx";
                        break;
                    case 9:
                        url = "PicNewsList.aspx";
                        break;
                    case 10:
                        url = "UrlList.aspx";
                        break;
                    case 11:
                        url = "ManageList.aspx";
                        break;
                    default:
                        url = "";
                        break;
                }
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = url
                    + "?secondid=" + LTP.Common.StringClass.EncodeUrl(((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString());
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Attributes.Add("onclick", "SubMenuClick('" + ((HtmlControl)e.Item.FindControl("liItem")).ClientID + "')");
            }
        }
    }
}